<?php

/**
* Property file reader
* 
* @author b3ha (baloghbh@gmail.com)
*/
function property_reader($file_name, $format = '=')
{
    // key => value
    $properties     = array();
    // lines
    $content        = file($file_name);
    // next line belongs prev line's value
    $line_continues = FALSE;	

    foreach ($content as $line)
    {
        // check unimportant lines
        switch ($line[0])
        {
            case '':
            case "\n":
            case '!':
            case '#':
            {
                // empty or commented line
                continue 2;
            }
            break;
        }

        // --- important contents from here ---

        // simple property
        $key	= trim(strstr($line, $format, TRUE));
        $value	= trim(substr(strstr($line, $format, FALSE), 1));
        // this line is the next part of the prev line's
        if ($line_continues)
        {
            $key    = $line_continues;
            $value  = $properties[$key] . ' ' . trim($line);
        }

        $value = preg_replace('/\\\\u([0-9a-f]{4})/i', '&#x$1;', $value);

        // simple line
        $properties[$key]   = $value;
        $line_continues     = FALSE;
        // this line is continually
        if ($line[strlen($line)-2] === "\\")
        {
            $properties[$key] = substr($value, 0, -2);

            // root key for the continually property
            $line_continues = array_search(end($properties), $properties);
        }
    }

    return $properties;
}

# EOF
